package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_MJZFY;

public class GetEMR_MJZFYData {
	
	private static final Log log = LogFactory.getLog(GetEMR_MJZFYData.class);
	public static List<EMR_MJZFY> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_MJZFY> re = new ArrayList<EMR_MJZFY>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        
	        String sql = "select "
	        		+"a.yljgdm as JZJGDM,"
	        		+"a.jzlsh as MJZH,"
					+"'' as HZZSYH,"
					+"a.jsjlid as MJZFYLSH,"
					+"'' as XM,"
					+"'' as SZNL,"
					+"'' as XBDM,"
					+"a.fyjszje as MJZFYZJE,"
					+"to_char(a.fyjssj,'YYYY-MM-dd HH24:mi:ss') as MJZFYZFRQTFSJ,"
					+"a.zfje as GRCDFY,"
					+"'' as JZJGMC,"
					+"'' as JZKSDM,"
					+"'' as JZKSMC,"
					+"'' as JYLX,"
					+"'' as ZRLSH,"
					+"'' as CFBH,"
					+"a.jsfph as FPBH,"
					+"'' as SJBH,"
					+"'' as YLFYJSFSDM,"
					+"a.ylfkfs as YLFYZFFSDM,"
					+"to_char(a.ywscsj,'YYYY-MM-dd HH24:mi:ss') as BCRQ,"
					+"'' as ZRLSH,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+" from  TB_MZ_JSB  a ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
//	            System.out.println(result.getInt("YYDAH"));
	        	EMR_MJZFY temp = new EMR_MJZFY();
	        	temp.setJZJGDM(result.getString("JZJGDM"));
	        	temp.setMJZH(result.getString("MJZH"));
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setMJZFYLSH(result.getString("MJZFYLSH"));
	        	temp.setXM(result.getString("XM"));
	        	temp.setSZNL(result.getString("SZNL"));
	        	temp.setXBDM(result.getString("XBDM"));
	        	temp.setMJZFYZJE(result.getString("MJZFYZJE"));
	        	temp.setMJZFYZFRQTFSJ(result.getString("MJZFYZFRQTFSJ"));
	        	temp.setGRCDFY(result.getString("GRCDFY"));
	        	temp.setJZJGMC(result.getString("JZJGMC"));
	        	temp.setJZKSDM(result.getString("JZKSDM"));
	        	temp.setJZKSMC(result.getString("JZKSMC"));
	        	temp.setJYLX(result.getString("JYLX"));
	        	temp.setZRLSH(result.getString("ZRLSH"));
	        	temp.setCFBH(result.getString("CFBH"));
	        	temp.setFPBH(result.getString("FPBH"));
	        	temp.setSJBH(result.getString("SJBH"));
	        	temp.setYLFYJSFSDM(result.getString("YLFYJSFSDM"));
	        	temp.setYLFYZFFSDM(result.getString("YLFYZFFSDM"));
	        	temp.setBCRQ(result.getString("BCRQ"));
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
